package com.shaoxi.risk.domain.ability;

import com.shaoxi.ext.framework.ExtManager;
import com.shaoxi.risk.api.dto.PromotionDTO;
import com.shaoxi.risk.api.req.PriceRiskReq;
import com.shaoxi.risk.ext.sdk.PromotionFilterExt;
import com.shaoxi.risk.ext.sdk.PromotionPram;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 活动价计算能力
 */
@Component
public class PromotionPriceCalAbility {

    @Resource
    private ExtManager extManager;

    public Long calPromotionPrice(String bizCode, PriceRiskReq priceRiskReq){
        // 优惠过滤。 有些业务期望部分优惠不参与优惠计算，可以通过实现自己的扩展点定制
        PromotionFilterExt promotionFilterExt = extManager.getExt(bizCode, PromotionFilterExt.class);
        List<PromotionDTO> promotionDTOList = priceRiskReq.getPromotionDTOList().stream()
                .filter(promotionDTO -> promotionFilterExt.isFilter(buildPromotionParam(promotionDTO)))
                .collect(Collectors.toList());

        Long handPrice = calHandPrice(priceRiskReq, promotionDTOList);

        return handPrice;
    }

    private Long calHandPrice(PriceRiskReq priceRiskReq, List<PromotionDTO> promotionDTOList) {
        // TODO
        return null;
    }

    private PromotionPram buildPromotionParam(PromotionDTO promotionDTO) {
        //TODO
        return null;
    }
}
